﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;


namespace SPBusiness
{
   public sealed class ListItem
   {
      /// <summary>
      /// ListItem class has only Static Methods, no constructor needed.
      /// </summary>
      private ListItem() { }

      public static string GetNextVersion(SPListItem vSPListItem)
      {
         try
         {
            if (vSPListItem.Versions.Count > 0)
            {
               int vVersionId = vSPListItem.Versions[0].VersionId;

               return ((vVersionId + 512) / 512).ToString() + ".0";

            }
            else { return "1.0"; }

         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "GetNextVersion", ex);
            throw;
         }
      }

      public static void RemoveAllUsersPermissions(SPListItem pSPListItem)
      {
         try
         {
            if (pSPListItem != null)
            {
               //SPSecurity.RunWithElevatedPrivileges(delegate()
               //{
                  using (SPSite vSPSite = new SPSite(pSPListItem.Web.Site.Url))
                  {
                     using (SPWeb vSPWeb = vSPSite.OpenWeb(pSPListItem.Web.ID))
                     {
                        SPList vSPList = vSPWeb.Lists[pSPListItem.ParentList.ID];
                        SPListItem vSPListItem = vSPList.GetItemById(pSPListItem.ID);

                        if (!vSPListItem.HasUniqueRoleAssignments)
                        {
                           vSPListItem.BreakRoleInheritance(true, true);
                        }

                        SPRoleAssignment vSPRoleAssignment = null;

                        for (int k = vSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
                        {
                           vSPRoleAssignment = vSPListItem.RoleAssignments[k];
                           SPPrincipal vSPPrincipal = vSPRoleAssignment.Member;
                           if (vSPPrincipal.Name != vSPPrincipal.LoginName)
                           {
                              vSPListItem.RoleAssignments.Remove(k);
                           }
                        }

                        ListItem.RealSystemUpdate(vSPListItem);
                     }

                  }
               //});
            }
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "RemoveAllUsersPermissions", ex);
            throw;
         }
      }

      public static void RemoveAllPermissions(SPListItem pSPListItem, SPPrincipal pSPPrincipal)
      {
         try
         {
            if (pSPListItem != null)
            {
               //SPSecurity.RunWithElevatedPrivileges(delegate()
                   //{
                      using (SPSite vSPSite = new SPSite(pSPListItem.Web.Site.Url))
                      {
                         using (SPWeb vSPWeb = vSPSite.OpenWeb(pSPListItem.Web.ID))
                         {
                            SPList vSPList = vSPWeb.Lists[pSPListItem.ParentList.ID];
                            SPListItem vSPListItem = vSPList.GetItemById(pSPListItem.ID);

                            if (!vSPListItem.HasUniqueRoleAssignments)
                            {
                               vSPListItem.BreakRoleInheritance(true, true);
                            }

                            SPRoleAssignment vSPRoleAssignment = null;

                            for (int k = vSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
                            {
                               vSPRoleAssignment = vSPListItem.RoleAssignments[k];

                               if (vSPRoleAssignment.Member.ID == pSPPrincipal.ID)
                               {
                                  vSPListItem.RoleAssignments.Remove(k);
                               }
                            }

                            ListItem.RealSystemUpdate(vSPListItem);
                         }

                      }
                   //});
            }
         }
         catch (Exception ex)
         {

            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "RemoveAllPermissions", ex);
            throw;
         }
      }

      public static void SetPermission(SPListItem pSPListItem, SPPrincipal pSPPrincipal, SPRoleType pSPRoleType)
      {
         try
         {
            if (pSPListItem != null)
            {
               //SPSecurity.RunWithElevatedPrivileges(delegate()
                  // {
                      using (SPSite vSPSite = new SPSite(pSPListItem.Web.Site.Url))
                      {
                         using (SPWeb vSPWeb = vSPSite.OpenWeb(pSPListItem.Web.ID))
                         {
                            SPList vSPList = vSPWeb.Lists[pSPListItem.ParentList.ID];
                            SPListItem vSPListItem = vSPList.GetItemById(pSPListItem.ID);

                            if (!vSPListItem.HasUniqueRoleAssignments)
                            {
                               vSPListItem.BreakRoleInheritance(true, true);
                            }

                            SPRoleAssignment vSPRoleAssignment = null;
                            SPRoleDefinition vSPRoleDefinition = null;

                            SPRoleDefinition vSPRoleDefinitionToAdd = vSPListItem.Web.RoleDefinitions.GetByType(pSPRoleType);

                            bool vFound = false;

                            for (int k = vSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
                            {
                               vSPRoleAssignment = vSPListItem.RoleAssignments[k];

                               if (vSPRoleAssignment.Member.ID == pSPPrincipal.ID)
                               {
                                  for (int i = vSPRoleAssignment.RoleDefinitionBindings.Count - 1; i >= 0; i--)
                                  {
                                     vSPRoleDefinition = vSPRoleAssignment.RoleDefinitionBindings[i];
                                     if (vSPRoleDefinition.Name != vSPRoleDefinitionToAdd.Name)
                                     {
                                        vSPRoleAssignment.RoleDefinitionBindings.Remove(i);
                                        vSPRoleAssignment.Update();
                                     }
                                     else
                                     {
                                        vFound = true;
                                     }
                                  }
                                  if (vSPRoleAssignment.RoleDefinitionBindings.Count == 0)
                                  {
                                     vSPListItem.RoleAssignments.Remove(k);
                                     ListItem.RealSystemUpdate(vSPListItem);
                                  }
                               }
                            }

                            if (!vFound)
                            {
                               vSPRoleAssignment = new SPRoleAssignment(pSPPrincipal);

                               vSPRoleAssignment.RoleDefinitionBindings.Add(vSPRoleDefinitionToAdd);

                               vSPListItem.RoleAssignments.Add(vSPRoleAssignment);

                               ListItem.RealSystemUpdate(vSPListItem);
                            }

                         }
                      }
                   //});
            }
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "SetPermission", ex);
            throw;
         }
      }

      public static void SetPermission(SPListItem pSPListItem, SPPrincipal pSPPrincipal, string pSPRoleType)
      {
         try
         {
            if (pSPListItem != null)
            {
               //SPSecurity.RunWithElevatedPrivileges(delegate()
              // {
                  using (SPSite vSPSite = new SPSite(pSPListItem.Web.Site.Url))
                  {
                     using (SPWeb vSPWeb = vSPSite.OpenWeb(pSPListItem.Web.ID))
                     {
                        SPList vSPList = vSPWeb.Lists[pSPListItem.ParentList.ID];
                        SPListItem vSPListItem = vSPList.GetItemById(pSPListItem.ID);

                        if (!vSPListItem.HasUniqueRoleAssignments)
                        {
                           vSPListItem.BreakRoleInheritance(true, true);
                        }

                        SPRoleAssignment vSPRoleAssignment = null;
                        SPRoleDefinition vSPRoleDefinition = null;

                        SPRoleDefinition vSPRoleDefinitionToAdd = pSPListItem.Web.RoleDefinitions[pSPRoleType];

                        bool vFound = false;

                        for (int k = vSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
                        {
                           vSPRoleAssignment = vSPListItem.RoleAssignments[k];

                           if (vSPRoleAssignment.Member.ID == pSPPrincipal.ID)
                           {
                              for (int i = vSPRoleAssignment.RoleDefinitionBindings.Count - 1; i >= 0; i--)
                              {
                                 vSPRoleDefinition = vSPRoleAssignment.RoleDefinitionBindings[i];
                                 if (vSPRoleDefinition.Name != vSPRoleDefinitionToAdd.Name)
                                 {
                                    vSPRoleAssignment.RoleDefinitionBindings.Remove(i);
                                    vSPRoleAssignment.Update();
                                 }
                                 else
                                 {
                                    vFound = true;
                                 }
                              }
                              if (vSPRoleAssignment.RoleDefinitionBindings.Count == 0)
                              {
                                 vSPListItem.RoleAssignments.Remove(k);
                                 ListItem.RealSystemUpdate(vSPListItem);
                              }
                           }
                        }

                        if (!vFound)
                        {
                           vSPRoleAssignment = new SPRoleAssignment(pSPPrincipal);

                           vSPRoleAssignment.RoleDefinitionBindings.Add(vSPRoleDefinitionToAdd);

                           vSPListItem.RoleAssignments.Add(vSPRoleAssignment);

                           ListItem.RealSystemUpdate(vSPListItem);
                        }

                     }
                  }
               //});
            }
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "SetPermission", ex);
            throw;
         }
      }

      public static void RemoveAllUsersPermissionsNotUpdate(SPListItem pSPListItem)
      {
         try
         {

            if (!pSPListItem.HasUniqueRoleAssignments)
            {
               pSPListItem.BreakRoleInheritance(true, true);
            }

            SPRoleAssignment vSPRoleAssignment = null;

            for (int k = pSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
            {
               vSPRoleAssignment = pSPListItem.RoleAssignments[k];
               SPPrincipal vSPPrincipal = vSPRoleAssignment.Member;
               if (vSPPrincipal.Name != vSPPrincipal.LoginName)
               {
                  pSPListItem.RoleAssignments.Remove(k);
               }
            }

         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "RemoveAllUsersPermissionsNotUpdate", ex);
            throw;
         }
      }

      public static void RemoveAllPermissionsNotUpdate(SPListItem pSPListItem, SPPrincipal pSPPrincipal)
      {
         try
         {
            if (!pSPListItem.HasUniqueRoleAssignments)
            {
               pSPListItem.BreakRoleInheritance(true, true);
            }

            SPRoleAssignment vSPRoleAssignment = null;

            for (int k = pSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
            {
               vSPRoleAssignment = pSPListItem.RoleAssignments[k];

               if (vSPRoleAssignment.Member.ID == pSPPrincipal.ID)
               {
                  pSPListItem.RoleAssignments.Remove(k);
               }
            }


         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "RemoveAllPermissionsNotUpdate", ex);
            throw;
         }
      }

      public static void SetPermissionNotUpdate(SPListItem pSPListItem, SPPrincipal pSPPrincipal, SPRoleType pSPRoleType)
      {
         try
         {

            if (!pSPListItem.HasUniqueRoleAssignments)
            {
               pSPListItem.BreakRoleInheritance(true, true);
            }

            SPRoleAssignment vSPRoleAssignment = null;
            SPRoleDefinition vSPRoleDefinition = null;

            SPRoleDefinition vSPRoleDefinitionToAdd = pSPListItem.Web.RoleDefinitions.GetByType(pSPRoleType);

            bool vFound = false;

            for (int k = pSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
            {
               vSPRoleAssignment = pSPListItem.RoleAssignments[k];

               if (vSPRoleAssignment.Member.ID == pSPPrincipal.ID)
               {
                  for (int i = vSPRoleAssignment.RoleDefinitionBindings.Count - 1; i >= 0; i--)
                  {
                     vSPRoleDefinition = vSPRoleAssignment.RoleDefinitionBindings[i];
                     if (vSPRoleDefinition.Name != vSPRoleDefinitionToAdd.Name)
                     {
                        vSPRoleAssignment.RoleDefinitionBindings.Remove(i);
                        vSPRoleAssignment.Update();
                     }
                     else
                     {
                        vFound = true;
                     }
                  }
                  if (vSPRoleAssignment.RoleDefinitionBindings.Count == 0)
                  {
                     pSPListItem.RoleAssignments.Remove(k);
                  }
               }
            }

            if (!vFound)
            {
               vSPRoleAssignment = new SPRoleAssignment(pSPPrincipal);

               vSPRoleAssignment.RoleDefinitionBindings.Add(vSPRoleDefinitionToAdd);

               pSPListItem.RoleAssignments.Add(vSPRoleAssignment);

            }
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "SetPermissionNotUpdate", ex);
            throw;
         }
      }

      public static void SetPermissionNotUpdate(SPListItem pSPListItem, SPPrincipal pSPPrincipal, string pSPRoleType)
      {
         try
         {


            if (!pSPListItem.HasUniqueRoleAssignments)
            {
               pSPListItem.BreakRoleInheritance(true, true);
            }

            SPRoleAssignment vSPRoleAssignment = null;
            SPRoleDefinition vSPRoleDefinition = null;

            SPRoleDefinition vSPRoleDefinitionToAdd = pSPListItem.Web.RoleDefinitions[pSPRoleType];

            bool vFound = false;

            for (int k = pSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
            {
               vSPRoleAssignment = pSPListItem.RoleAssignments[k];

               if (vSPRoleAssignment.Member.ID == pSPPrincipal.ID)
               {
                  for (int i = vSPRoleAssignment.RoleDefinitionBindings.Count - 1; i >= 0; i--)
                  {
                     vSPRoleDefinition = vSPRoleAssignment.RoleDefinitionBindings[i];
                     if (vSPRoleDefinition.Name != vSPRoleDefinitionToAdd.Name)
                     {
                        vSPRoleAssignment.RoleDefinitionBindings.Remove(i);
                        vSPRoleAssignment.Update();
                     }
                     else
                     {
                        vFound = true;
                     }
                  }
                  if (vSPRoleAssignment.RoleDefinitionBindings.Count == 0)
                  {
                     pSPListItem.RoleAssignments.Remove(k);
                  }
               }
            }

            if (!vFound)
            {
               vSPRoleAssignment = new SPRoleAssignment(pSPPrincipal);

               vSPRoleAssignment.RoleDefinitionBindings.Add(vSPRoleDefinitionToAdd);

               pSPListItem.RoleAssignments.Add(vSPRoleAssignment);

            }

         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "SetPermissionNotUpdate", ex);
            throw;
         }
      }

      public static void SetPermissionNotElevated(SPListItem pSPListItem, SPPrincipal pSPPrincipal, SPRoleType pSPRoleType)
      {
         try
         {
            if (pSPListItem != null)
            {

               if (!pSPListItem.HasUniqueRoleAssignments)
               {
                  pSPListItem.BreakRoleInheritance(true, true);
               }

               SPRoleAssignment vSPRoleAssignment = null;
               SPRoleDefinition vSPRoleDefinition = null;

               SPRoleDefinition vSPRoleDefinitionToAdd = pSPListItem.Web.RoleDefinitions.GetByType(pSPRoleType);

               bool vFound = false;

               for (int k = pSPListItem.RoleAssignments.Count - 1; k >= 0; k--)
               {
                  vSPRoleAssignment = pSPListItem.RoleAssignments[k];

                  if (vSPRoleAssignment.Member.ID == pSPPrincipal.ID)
                  {
                     for (int i = vSPRoleAssignment.RoleDefinitionBindings.Count - 1; i >= 0; i--)
                     {
                        vSPRoleDefinition = vSPRoleAssignment.RoleDefinitionBindings[i];
                        if (vSPRoleDefinition.Name != vSPRoleDefinitionToAdd.Name)
                        {
                           vSPRoleAssignment.RoleDefinitionBindings.Remove(i);
                           vSPRoleAssignment.Update();
                        }
                        else
                        {
                           vFound = true;
                        }
                     }
                     if (vSPRoleAssignment.RoleDefinitionBindings.Count == 0)
                     {
                        pSPListItem.RoleAssignments.Remove(k);

                        ListItem.RealSystemUpdate(pSPListItem);
                     }
                  }
               }

               if (!vFound)
               {
                  vSPRoleAssignment = new SPRoleAssignment(pSPPrincipal);

                  vSPRoleAssignment.RoleDefinitionBindings.Add(vSPRoleDefinitionToAdd);

                  pSPListItem.RoleAssignments.Add(vSPRoleAssignment);

                  ListItem.RealSystemUpdate(pSPListItem);
               }

            }
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "SetPermissionNotElevated", ex);
            throw;
         }
      }

      public static SPListItem GetWithElevatedPrivileges(SPListItem pSPListItem)
      {
         try
         {

            SPListItem vSPListItem = null;

            //SPSecurity.RunWithElevatedPrivileges(delegate()
           // {
               using (SPSite vSPSite = new SPSite(pSPListItem.Web.Site.Url))
               {
                  using (SPWeb vSPWeb = vSPSite.OpenWeb(pSPListItem.Web.ID))
                  {
                     SPList vSPList = vSPWeb.Lists[pSPListItem.ParentList.ID];
                     vSPListItem = vSPList.GetItemById(pSPListItem.ID);

                  }

               }
            //});

            return vSPListItem;

         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "GetWithElevatedPrivileges", ex);
            throw;
         }
      }

      public static SPListItem InstanciateByEditor(string pSiteUrl, string pWebRelative, Int32 pID, string pListTitle)
      {
         try
         {
            SPUserToken vSPUserToken = null;
            SPListItem vReturn = null;

            //SPSecurity.RunWithElevatedPrivileges(delegate()
        //  {

             using (SPSite vSPSite = new SPSite(pSiteUrl))
             {
                using (SPWeb vSPWeb = vSPSite.OpenWeb(pWebRelative))
                {

                   SPList vSPList = vSPWeb.Lists.TryGetList(pListTitle);

                   if (vSPList != null)
                   {
                      SPListItem vSPListItem = vSPList.GetItemById(pID);
                      vSPUserToken = vSPWeb.AllUsers.GetByID(new SPFieldLookupValue(vSPListItem["Editor"].ToString()).LookupId).UserToken;
                   }

                }
             }
          //});

            if (vSPUserToken != null)
            {
               using (SPSite vSPSite = new SPSite(pSiteUrl, vSPUserToken))
               {
                  using (SPWeb vSPWeb = vSPSite.OpenWeb(pWebRelative))
                  {
                     SPList vSPList = vSPWeb.Lists.TryGetList(pListTitle);
                     vReturn = vSPList.GetItemById(pID);
                  }
               }
            }

            return vReturn;
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "InstanciateByEditor", ex);
            throw;
         }


      }

      public static SPListItem InstanciateByCheckOutUser(SPListItem pSPListItem)
      {
         try
         {
            SPUserToken vSPUserToken = null;

            if (pSPListItem.File.CheckedOutByUser != null)
            {
               vSPUserToken = pSPListItem.File.CheckedOutByUser.UserToken;
            }

            if (vSPUserToken != null)
            {
               using (SPSite vSPSite = new SPSite(pSPListItem.Web.Site.Url, vSPUserToken))
               {
                  using (SPWeb vSPWeb = vSPSite.OpenWeb(pSPListItem.Web.ID))
                  {

                     SPList vSPList = vSPWeb.Lists[pSPListItem.ParentList.ID];
                     return vSPList.GetItemById(pSPListItem.ID);
                  }
               }
            }
            return null;
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "InstanciateByCheckOutUser", ex);
            throw;
         }
      }

      public static SPListItem InstanciateByUser(string pSiteUrl, string pWebRelative, Int32 pID, string pListTitle, string pLoginName)
      {
         try
         {
            SPUserToken vSPUserToken = null;
            SPListItem vReturn = null;

            //SPSecurity.RunWithElevatedPrivileges(delegate()
            //{
               using (SPSite vSPSite = new SPSite(pSiteUrl))
               {
                  using (SPWeb vSPWeb = vSPSite.OpenWeb(pWebRelative))
                  {
                     vSPUserToken = vSPWeb.EnsureUser(pLoginName).UserToken;
                  }
               }
            //});

            if (vSPUserToken != null)
            {
               using (SPSite vSPSite = new SPSite(pSiteUrl, vSPUserToken))
               {
                  using (SPWeb vSPWeb = vSPSite.OpenWeb(pWebRelative))
                  {
                     SPList vSPList = vSPWeb.Lists.TryGetList(pListTitle);
                     vReturn = vSPList.GetItemById(pID);
                  }
               }
            }

            return vReturn;
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "InstanciateByUser", ex);
            throw;
         }


      }

      public static SPListItem InstanciateElevated(string pSiteUrl, string pWebRelative, Int32 pID, string pListTitle)
      {
         try
         {
            SPListItem vReturn = null;

            //SPSecurity.RunWithElevatedPrivileges(delegate()
            //{
               using (SPSite vSPSite = new SPSite(pSiteUrl))
               {
                  using (SPWeb vSPWeb = vSPSite.OpenWeb(pWebRelative))
                  {
                     SPList vSPList = vSPWeb.Lists.TryGetList(pListTitle);
                     vReturn = vSPList.GetItemById(pID);
                  }
               }
            //});

            return vReturn;
         }
         catch (Exception ex)
         {
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "InstanciateElevated", ex);
            throw;
         }


      }

      public static void RealSystemUpdate(SPListItem pSPListItem)
      {

         SPEventFiring vSPDisableEventFiring = null;

         try
         {
            using (vSPDisableEventFiring = new SPEventFiring(false))
            {
               pSPListItem.SystemUpdate(false);
            }
         }
         catch (Exception ex)
         {
            if (vSPDisableEventFiring != null) { vSPDisableEventFiring.Dispose(); }
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "RealSystemUpdate", ex);
            throw;
         }


      }

      public static void SystemUpdateWithOutEvent(SPListItem pSPListItem, bool pIncrementVersion)
      {

         SPEventFiring vSPDisableEventFiring = null;

         try
         {
            using (vSPDisableEventFiring = new SPEventFiring(false))
            {
               pSPListItem.SystemUpdate(pIncrementVersion);
            }
         }
         catch (Exception ex)
         {
            if (vSPDisableEventFiring != null) { vSPDisableEventFiring.Dispose(); }
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "SystemUpdateWithOutEvent", ex);
            throw;
         }


      }

      public static void UpdateOverwriteVersionNotEvent(SPListItem pSPListItem)
      {
         SPEventFiring vSPDisableEventFiring = null;

         try
         {
            using (vSPDisableEventFiring = new SPEventFiring(false))
            {
               pSPListItem.UpdateOverwriteVersion();
            }
         }
         catch (Exception ex)
         {
            if (vSPDisableEventFiring != null) { vSPDisableEventFiring.Dispose(); }
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "UpdateOverwriteVersionNotEvent", ex);
            throw;
         }


      }

      public static void UpdateNotEvent(SPListItem pSPListItem)
      {

         SPEventFiring vSPDisableEventFiring = null;

         try
         {
            using (vSPDisableEventFiring = new SPEventFiring(false))
            {
               pSPListItem.Update();
            }
         }
         catch (Exception ex)
         {
            if (vSPDisableEventFiring != null) { vSPDisableEventFiring.Dispose(); }
            Logging.LogMessase(typeof(ListItem).Namespace, typeof(ListItem).Name, "UpdateNotEvent", ex);
            throw;
         }
      }
   }
}
